#include "user.h"

User::User(const QString& username , const QString& password )
    : m_username(username),m_password(password){}
QString User::getUsername() const
{
    return m_username;
}

void User::setUsername(const QString &username)
{
    m_username = username;
}

QString User::getPassword() const
{
    return m_password;
}

void User::setPassword(const QString &password)
{
    m_password = password;
}


bool User::validateUser(const QString &username, const QString &password)
{
    for (const auto& user : registeredUsers)
    {
        if (user.getUsername() == username && user.getPassword() == password)
        {
            return true;
        }
    }
    return false;
}

bool User::userExists(const QString &username)
{
    for (const auto& user : registeredUsers)
    {
        if (user.getUsername() == username)
            return true;
    }
    return false;
}

void User::save()
{
    registeredUsers.append(*this);
}

//初始化一些用户
QList<User> User::registeredUsers =
{
    User("admin","password123"),
    User("user1", "pass1"),
    User("user2", "pass2")
};
